/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package NewGUI;

import Control.Database;
import Control.User;
import java.awt.Dimension;
import java.awt.Toolkit;

/**
 *
 * @author dodan_000
 */
public class MainUI extends javax.swing.JFrame {

    /**
     * Creates new form MainUI
     */
    Login login;
    User user ;
    Account account;
    AddTransaction addTransaction ;
    Category category;
    Project project = new Project();
    Statistics statistics;
    
    public MainUI() {
        initComponents();
        Database.setState(); //test
        User user = new User();
        user.userName="hien";
        user.id=1;
        account = new Account(user);
    }

    public MainUI(User user,Login login){
        this.login = login;
        this.user = user;
        initComponents();
        
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        
        int w = this.getWidth();
        int h = this.getHeight();
        int x = (dim.width-w)/2;
        int y = (dim.height-h)/2;
        this.setLocation(x, y);        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnStatistics = new javax.swing.JButton();
        btnCategory = new javax.swing.JButton();
        btnProject = new javax.swing.JButton();
        btnAccount = new javax.swing.JButton();
        btnAddTransaction = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbAccountsSummary = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        menuItemQuit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();

        setMaximumSize(new java.awt.Dimension(890, 560));
        setMinimumSize(new java.awt.Dimension(890, 560));
        setPreferredSize(new java.awt.Dimension(890, 560));
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                formFocusGained(evt);
            }
        });

        jPanel1.setMaximumSize(new java.awt.Dimension(32767, 60));
        jPanel1.setMinimumSize(new java.awt.Dimension(890, 60));
        jPanel1.setPreferredSize(new java.awt.Dimension(890, 60));
        jPanel1.setLayout(null);

        btnStatistics.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnStatistics.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/barChart 24.png"))); // NOI18N
        btnStatistics.setText("Statistics");
        btnStatistics.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnStatistics.setMaximumSize(new java.awt.Dimension(60, 60));
        btnStatistics.setMinimumSize(new java.awt.Dimension(60, 60));
        btnStatistics.setPreferredSize(new java.awt.Dimension(60, 60));
        btnStatistics.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnStatistics.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnStatistics.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStatisticsActionPerformed(evt);
            }
        });
        jPanel1.add(btnStatistics);
        btnStatistics.setBounds(80, 0, 80, 60);

        btnCategory.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnCategory.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/category 24.png"))); // NOI18N
        btnCategory.setText("Category");
        btnCategory.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCategory.setMaximumSize(new java.awt.Dimension(60, 60));
        btnCategory.setMinimumSize(new java.awt.Dimension(60, 60));
        btnCategory.setPreferredSize(new java.awt.Dimension(60, 60));
        btnCategory.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnCategory.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel1.add(btnCategory);
        btnCategory.setBounds(240, 0, 90, 60);

        btnProject.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnProject.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/add project 24.png"))); // NOI18N
        btnProject.setText("Project");
        btnProject.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnProject.setMaximumSize(new java.awt.Dimension(60, 60));
        btnProject.setMinimumSize(new java.awt.Dimension(60, 60));
        btnProject.setPreferredSize(new java.awt.Dimension(60, 60));
        btnProject.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnProject.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProjectActionPerformed(evt);
            }
        });
        jPanel1.add(btnProject);
        btnProject.setBounds(330, 0, 80, 60);

        btnAccount.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnAccount.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/account 24.png"))); // NOI18N
        btnAccount.setText("Account");
        btnAccount.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAccount.setMaximumSize(new java.awt.Dimension(60, 60));
        btnAccount.setMinimumSize(new java.awt.Dimension(60, 60));
        btnAccount.setPreferredSize(new java.awt.Dimension(60, 60));
        btnAccount.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnAccount.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAccountActionPerformed(evt);
            }
        });
        jPanel1.add(btnAccount);
        btnAccount.setBounds(160, 0, 78, 60);

        btnAddTransaction.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnAddTransaction.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/add-24.png"))); // NOI18N
        btnAddTransaction.setText("Add");
        btnAddTransaction.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAddTransaction.setMaximumSize(new java.awt.Dimension(60, 60));
        btnAddTransaction.setMinimumSize(new java.awt.Dimension(60, 60));
        btnAddTransaction.setPreferredSize(new java.awt.Dimension(60, 60));
        btnAddTransaction.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        btnAddTransaction.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAddTransaction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddTransactionActionPerformed(evt);
            }
        });
        jPanel1.add(btnAddTransaction);
        btnAddTransaction.setBounds(0, 0, 78, 60);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Accounts summary");

        tbAccountsSummary.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Account", "Income", "Expense", "Budget"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbAccountsSummary);

        jLabel2.setText("Message");

        jMenu1.setText("File");

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/logout.png"))); // NOI18N
        jMenuItem5.setText("Logout");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        menuItemQuit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/quit.png"))); // NOI18N
        menuItemQuit.setText("Quit");
        menuItemQuit.setToolTipText("Exit Program");
        menuItemQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemQuitActionPerformed(evt);
            }
        });
        jMenu1.add(menuItemQuit);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem1.setText("Preferences");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Manage");

        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/account 24.png"))); // NOI18N
        jMenuItem3.setText("Accounts");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuBar1.add(jMenu3);

        jMenu4.setText("Report");

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/barChart 24.png"))); // NOI18N
        jMenuItem2.setText("Statistics");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem2);

        jMenuBar1.add(jMenu4);

        jMenu5.setText("Help");

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/main/about.png"))); // NOI18N
        jMenuItem4.setText("About");
        jMenu5.add(jMenuItem4);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 271, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProjectActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnProjectActionPerformed

    private void btnAddTransactionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddTransactionActionPerformed
        // TODO add your handling code here:
        
        addTransaction = new AddTransaction(user);
        addTransaction.setVisible(true);   
    }//GEN-LAST:event_btnAddTransactionActionPerformed

    private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
        // TODO add your handling code here:
 
        
    }//GEN-LAST:event_formFocusGained

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
        try{
        if(!addTransaction.isVisible()){
            System.out.println(addTransaction.getDescription());
        }
        }
        catch(Exception ex){
            
        }
    }//GEN-LAST:event_formWindowGainedFocus

    private void btnStatisticsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStatisticsActionPerformed
        // TODO add your handling code here:
        statistics = new Statistics(user);
        statistics.setVisible(true);
    }//GEN-LAST:event_btnStatisticsActionPerformed

    private void btnAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAccountActionPerformed
        // TODO add your handling code here:
        account = new Account(user);
        account.setVisible(true);
    }//GEN-LAST:event_btnAccountActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        btnStatisticsActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        btnAccountActionPerformed(evt);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void menuItemQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemQuitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_menuItemQuitActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        // TODO add your handling code here:
        login.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAccount;
    private javax.swing.JButton btnAddTransaction;
    private javax.swing.JButton btnCategory;
    private javax.swing.JButton btnProject;
    private javax.swing.JButton btnStatistics;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenuItem menuItemQuit;
    private javax.swing.JTable tbAccountsSummary;
    // End of variables declaration//GEN-END:variables
}
